CMAKE_MINIMUM_REQUIRED(VERSION 2.8)

include_directories(${COMN_DIR}/include)
include_directories(${FFMPEG_DIR}/include)
include_directories(.)

if (MSVC)
include_directories(${THIRD_PARTY}/stdint)
endif()

include_directories(${THIRD_PARTY}/tinyxml)
include_directories(${THIRD_PARTY}/jsoncpp-0.10.6/include)
include_directories(${THIRD_PARTY}/HK8200/include)
include_directories(${THIRD_PARTY}/hk)
include_directories(${THIRD_PARTY}/speex/include)

link_directories(${PROJECT_ROOT}/lib)
link_directories(${COMN_DIR}/lib)
link_directories(${FFMPEG_LIB_DIR})
link_directories(${FFMPEG_DIR}/bin)
link_directories(${THIRD_PARTY}/jrtplib/lib)
link_directories(${THIRD_PARTY}/tinyxml/lib)
link_directories(${RESIP_DIR}/rutil/.libs)
link_directories(${RESIP_DIR}/rutil/dns/ares/.libs)
link_directories(${RESIP_DIR}/resip/stack/.libs)
link_directories(${RESIP_DIR}/resip/dum/.libs)
link_directories(${THIRD_PARTY}/openssl/lib)

link_directories(${THIRD_PARTY}/HK8200/lib)
link_directories(${THIRD_PARTY}/hk)

include_directories(${PROJECT_ROOT}/CrashDump)

if (WIN32)
    include_directories(${THIRD_PARTY}/jrtplib/include/jrtplib3)
    set(LIB_JRTP debug jrtplib_d optimized jrtplib)
else (WIN32)
    include_directories(${THIRD_PARTY}/jrtplib/linux/jrtplib3)
    set(LIB_JRTP jrtp)
endif (WIN32)


include_directories(util)
include_directories(media)
include_directories(rtp)
include_directories(db)
include_directories(http)


aux_source_directory(. SOURCES)
aux_source_directory(util SOURCES)
aux_source_directory(media SOURCES)
aux_source_directory(rtp SOURCES)
aux_source_directory(db SOURCES)
aux_source_directory(http SOURCES)

add_executable(HkGate ${SOURCES})

if (MSVC)
	SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO")
endif()

if (CMAKE_HOST_WIN32)
	set(LIB_PLATFORM ${LIB_PLATFORM} Ws2_32 Dnsapi Iphlpapi winmm)
endif()

target_link_libraries(HkGate
	${LIB_FFMPEG}
	${LIB_PLATFORM}
	${CRASHDUMP_LIB}
	debug comnd optimized comn
	debug tinyxmld optimized tinyxml
	debug rutild optimized rutil
	debug aresd optimized ares
	debug resiprocated optimized resiprocate
	debug dumd optimized dum
	debug jrtplib_d optimized jrtplib
	debug jsoncppd optimized jsoncpp
	StdClient_Hikvision30
	HCNetSDK
	debug speexd optimized speex
	debug CrashDumpd optimized CrashDump
	)

install(TARGETS HkGate DESTINATION .)

install(FILES ${PROJECT_ROOT}/setup/HkGate.conf DESTINATION .)


if(WIN32)
	install(FILES ${PROJECT_ROOT}/setup/CrashReport.bat DESTINATION .)
	
	install(DIRECTORY ${THIRD_PARTY}/ffmpeg/bin/ DESTINATION . FILES_MATCHING PATTERN "*.dll")
	
	install(FILES ${THIRD_PARTY}/sqlite/bin/sqlite3.dll DESTINATION .)
	
	install(DIRECTORY ${THIRD_PARTY}/HK8200/bin/ DESTINATION . FILES_MATCHING PATTERN "*.*")
	install(DIRECTORY ${THIRD_PARTY}/HK8200/lib/ DESTINATION . FILES_MATCHING PATTERN "*.dll")
else()
	

		
endif()

set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION .)
include(InstallRequiredSystemLibraries)

#set(CPACK_PACKAGE_DIRECTORY ${PROJECT_ROOT})
set(CPACK_PACKAGE_NAME "HkGate")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "sip linker server")
set(CPACK_PACKAGE_VENDOR "100wits.com")
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "0")

if(UNIX)
	SET(CPACK_GENERATOR "TGZ")
else()
	SET(CPACK_GENERATOR "ZIP")
endif()

set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_CURRENT_SOURCE_DIR}/../dist") 
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}") 

include(CPack)